<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.min.js"></script>
</head>
<body>
<div style="padding: 100px">
    <div class="form-group">
        <label for="name">姓名</label>
        <input type="text" class="form-control" id="name" placeholder="请输入姓名">
    </div>
    <div class="form-group">
        <label for="address">地址</label>
        <input type="text" class="form-control" id="address" placeholder="请输入地址">
    </div>
    <div class="form-group">
        <label for="phone">手机号码</label>
        <input type="number" class="form-control" id="phone" placeholder="请输入手机号码">
    </div>

    <button onclick="save()" class="btn btn-default">确定</button>
    <button onclick="noDo()" class="btn">取消</button>
</div>
<script type="application/javascript">
    let id = null;
    function save() {
        $.ajax({
            url: '/sss/resume',
            type: "post",
            data: {
                "id": id,
                "name": $.trim($('#name').val()),
                "address": $.trim($('#address').val()),
                "phone": $.trim($('#phone').val())
            },
            datatype: "json",
            success: function (data) {
                window.location.href = "./resumeList.html";
            }
        })
    }

    function noDo() {
        window.location.href = "./resumeList.html";
    }

    /**
     * @return {string}
     */
    function GetQueryString(name) {
        const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        const r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    function init() {
        id = GetQueryString("id");
        if (id == null) {
            return
        }
        $.ajax({
            url: '/sss/resume/'+id,
            type: "get",
            data: {},
            datatype: "json",
            success: function (data) {
                $('#name').val(data.name);
                $('#address').val(data.address);
                $('#phone').val(data.phone);
            },
            error:function () {
                window.location.href="./index.html";
            }
        })
    }
    init();
</script>
</body>
</html>